<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>拼团商品添加</title>
    <!--  <link href="../assets/css/layer.css"  />-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet" />
    <link rel="stylesheet" href="../assets/css/bootstrapValidator.min.css" />
    <link rel="stylesheet" href="../assets/layui/layui-v2.5.4/css/layui.css"  media="all">
</head>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<style>
    th {
        text-align: center;
    }

    td {
        text-align: center;
    }

    tr {
        border: 1px solid #E6E6E6;
        line-height: 50px;
    }

    #tables{
        width: 100%;
    }


</style>
<body>

<div class="form-content">
    <br>
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-col-xs3 layui-col-xs-offset7" >
                <input type="text" id="mh" name="title" value=""   placeholder="请输入搜索内容" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-col-xs1">
                <button id="mh_select" value="" style="height: 36px;margin-top: 1px;width: 60px" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="mh_select">搜索</button>
            </div>
        </div>
    </div>
    <hr />
    <div class="layui-row">
        <div class="layui-col-xs12">

            <table    cellspacing="0" id="tables">
                <!-- <tr>
                     <th width="30%">产品名称</th>
                     <th width="10%">商品价格</th>
                     <th width="30%">商品库存</th>
                     <th width="30%">操作/状态</th>
                 </tr>-->
                <!--<tr>
                    <td>【奇异果】</td>
                    <td><input  type="text"  name="title" required  lay-verify="required"  autocomplete="off" class="layui-input"></td>
                    <td>【10】</td>
                    <td> <button  value="" style="height: 38px;width: 60px" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="mh_select">上架</button></td>
                </tr>-->
            </table>
        </div>
    </div>
</div>

<script src="../assets/js/jquery-3.4.1.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrapValidator.min.js"></script>
<script src="../assets/layui/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="../assets/js/layer.js"></script>
</body>

<script type="text/javascript">

    $(function () {
        queryWxGoodsStart();
    });

    var url=window.location.href;
    var spellId= url.substr(url.lastIndexOf("=")+1);
    function queryWxGoodsStart(str) {
        $.ajax({
            type:"get",
            url:"/wxSpellGoods/queryWxSpellGoods",
            data:{goodsName:str,spellId:spellId},
            success:function (result) {
                var   goods="";
                var   goodsTable='<tr>'+'<th width="30%">产品名称</th>'+'<th width="10%">拼团价</th>'+'<th width="30%">商品库存</th>'+'<th width="30%">操作/状态</th>'+'</tr>';
                $.each(result,function (i,v) {
                    if(v.spell_goods_state==0){
                        spell_goods_state="上架";
                       button=  '<button goodsId='+v.id+'  state='+v.spell_goods_state+' salesPrice='+v.spell_price+' name="bdGoods" value="" style="height: 38px;width: 60px" class="layui-btn layui-btn-normal layui-btn-sm  bdGoods" lay-event="bdGoods">'+spell_goods_state+'</button>'
                    }else{
                       spell_goods_state="下架";
                       button=  '<button goodsId='+v.id+'  state='+v.spell_goods_state+'  salesPrice='+v.spell_price+'  name="bdGoods" value="" style="height: 38px;width: 60px" class="layui-btn layui-btn-danger layui-btn-sm  bdGoods" lay-event="bdGoods">'+spell_goods_state+'</button>'
                    };
                    goods+= '<tr>'+ '<td>【'+v.goods_name+'】</td>'+ '<td class="abobo"><input type="text"  style="text-align: center;" name="salesPrice"   lay-verify="required" value='+v.spell_price+'  autocomplete="off" class="layui-input"></td>'+ '<td>【'+v.goods_num+'】</td>'+ '<td>'+button+'</td>'+ '</tr>'
                });
                $("#tables").html(goodsTable+goods);
                $(".bdGoods").on('click',function () {
                    var bt = $(this).parent().parent().children('.abobo').children().val();
                    var id = $(this).attr("goodsId");
                    var state=$(this).attr("state");
                   var salesPrice=bt;
                    // alert(salesPrice);
                    if(state==0)
                    {
                        state=1;
                    }else{
                        state=0;
                    }
                    upWxSpellGoods(id,state,salesPrice);
                });
            }
        });
    }

    function upWxSpellGoods(id,state,salesPrice)
    {
        $.ajax({
            type:"post",
            url:"/wxSpellGoods/upWxSpellGoods",
            data:{id:id,state:state,spellPrice:salesPrice},
            success:function (result) {
                if(result>0)
                {
                    parent.layer.msg('上架商品成功！');
                    queryWxGoodsStart();
                }else{
                    parent.layer.msg('上架商品失败！');
                }
            }
        });
    }

    $("#mh_select").on('click',function () {
        var  str =  $("#mh").val();
        queryWxGoodsStart(str);
    });

</script>
</html>
